package com.dtw.ditouwang.ui.mine

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.dtw.ditouwang.R
import com.dtw.ditouwang.beans.HelpBean
import com.dtw.ditouwang.ui.BaseActivity
import com.dtw.ditouwang.ui.OnItemClickListener
import kotlinx.android.synthetic.main.activity_help.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class HelpActivty : BaseActivity(), OnItemClickListener {
    var topSubDataBean = ArrayList<HelpBean.DataBean.SubDataBean>();
    var bottomSubDataBean = ArrayList<HelpBean.DataBean.SubDataBean>();
    var topAdapter = HelpAdapter(topSubDataBean)
    var bottomAdapter = HelpAdapter(bottomSubDataBean)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_help)
        enableBack()
        title = "帮助"
        recycler_top.adapter=topAdapter
        recycler_top.layoutManager=LinearLayoutManager(this)
        recycler_all.adapter=bottomAdapter
        recycler_all.layoutManager=LinearLayoutManager(this)
        topAdapter.onItemClickListener=this
        bottomAdapter.onItemClickListener=this


        webApi.helps.enqueue(object : Callback<HelpBean> {
            override fun onResponse(call: Call<HelpBean>, response: Response<HelpBean>) {
                var helpListBean = response.body();
                if (helpListBean != null && helpListBean.data != null) {
                    if (helpListBean.data.hot != null) {
                        topSubDataBean.clear()
                        topSubDataBean.addAll(helpListBean.data.hot)
                        topAdapter.notifyDataSetChanged()
                    }
                    if (helpListBean.data.question_type != null) {
                        bottomSubDataBean.clear()
                        bottomSubDataBean.addAll(helpListBean.data.question_type)
                        bottomAdapter.notifyDataSetChanged()
                    }
                }
            }

            override fun onFailure(call: Call<HelpBean>, t: Throwable) {

            }
        })
    }

    override fun onItemClick(resID: Int, position: Int, state: Int) {//resid是类别，state是id
        if(resID==0){
            var intent=Intent(this,HelpContentActivity::class.java)
            intent.putExtra(HelpContentActivity.KeyHelpConentID,state.toString())
            startActivity(intent)
        }else{
            var intent=Intent(this,HelpListActivity::class.java)
            intent.putExtra(HelpListActivity.KeyListID,state.toString())
            startActivity(intent);
        }
    }

}